package t496

import "sync"

// MyStack type
type MyStack struct {
	Items []int
	lock  sync.RWMutex
}

// RPush is func
func (m *MyStack) Push(x int) {
	m.lock.Lock()
	defer m.lock.Unlock()
	m.Items = append(m.Items, x)
}

// LPop is func
func (m *MyStack) Pop() int {
	m.lock.Lock()
	defer m.lock.Unlock()
	pop := m.Items[len(m.Items)-1]
	m.Items = m.Items[:len(m.Items)-1]
	return pop
}

// LTop is func
func (m *MyStack) Top() int {
	m.lock.Lock()
	defer m.lock.Unlock()
	return m.Items[len(m.Items)-1]
}

// Clear is func
func (m *MyStack) Clear() {
	m.lock.Lock()
	defer m.lock.Unlock()
	m.Items = make([]int, 0)
}
